package fr.vahren.dotastrat.game.command;

import java.util.Arrays;

import fr.vahren.dotastrat.game.D2SGame;
import fr.vahren.dotastrat.game.D2SMessageType;
import fr.vahren.dotastrat.model.D2SHeroUnit;
import fr.vahren.dotastrat.model.D2SMap;
import fr.vahren.dotastrat.model.D2SPlayer;
import fr.vahren.dotastrat.model.D2SZone;

public class D2SMoveCommande extends D2SCommand {

	public D2SMoveCommande(D2SPlayer player, D2SMap map, D2SHeroUnit hero,
			D2SZone dest, D2SGame g) {
		super(null, player, hero, map, null, dest, g);
		priority = 0; // moving is lowest priority
	}

	@Override
	public void execute() {
		int startZone = map.getZoneFromHero(unit.getId());
		if (map.canMoveTo(startZone, targetZone.getId())) {
			map.move(unit, startZone, targetZone.getId());
			String message = unit.getName() + " moves from zone " + startZone
					+ " to zone " + targetZone.getId();
			game.sendToAnyoneThatCanSee(unit.getId(),
					Arrays.asList(startZone, targetZone.getId()),
					player.getSide(), message, D2SMessageType.MOVE);
			unit.triggerMoveListener(startZone, targetZone.getId());
		}
	}
}
